package com.unittec.drainage.provider.auth.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;

import com.unittec.drainage.provider.auth.service.LimitFunctionService;
import com.unittec.drainage.provider.log.Log;

/**
 * @author: tangsicong
 * @date: 2019-6-25
 */
@RestController
public class LimitFunctionController {

    @Autowired
    Log log;

    @Autowired
    private LimitFunctionService limitFunctionService;
    /*
    @RequestMapping(value="/10031", method= RequestMethod.POST)
    @ApiOperation(value = "添加更新接口限流", notes = "添加更新接口限流")
    @ResponseBody
    public Result<Res10031> saveLimitFunction(@RequestBody GatewayRequest<Req10031> req) {
        log.debug(req, "saveLimitFunction {}  ",  "begin");
        BizCodeEnum bizCodeEnum= BizCode.ERROR;
        try {
            ValidationUtils.validateEntityStr(req.getContent());
            LimitFunction limitFunction = new LimitFunction();
            BeanUtils.copyProperties(req.getContent(), limitFunction);
            if (limitFunctionService.judgeLimitFunction(limitFunction)){
                bizCodeEnum= BizCode.SUCCESS;
            }
        } catch (Exception e) {
            log.error(req, e.toString(), e);
            return Result.error(req,e.toString());
        }
        log.debug(req, "saveLimitFunction {}  ",  "end");
        if (bizCodeEnum== BizCode.SUCCESS){
            return Result.success(req);
        }else {
            return Result.error(req,bizCodeEnum);
        }
    }
    
    
    @RequestMapping(value="/10033", method=RequestMethod.POST)
    @ApiOperation(value = "修改接口限流", notes = "修改接口限流")
    @ResponseBody
    public Result<Res10033> updateLimitFunction(@RequestBody GatewayRequest<Req10033> req) {
        log.debug(req, "updateLimitFunction {}  ",  "begin");
        BizCodeEnum bizCodeEnum= BizCode.ERROR;
        ValidationUtils.validateEntityStr(req.getContent());
        try {
            LimitFunction limitFunction = new LimitFunction();
            BeanUtils.copyProperties(req.getContent(), limitFunction);
            if (StringUtils.isBlank(limitFunctionService.getLimitFunction(req.getContent().getFunctionCode()))){
                bizCodeEnum= BizErrorCode101.NO_LIMIT_FUNCTION;
            }else {
                if (limitFunctionService.updateLimitFunction(limitFunction)){
                    bizCodeEnum= BizCode.SUCCESS;
                }
            }
    
        } catch (Exception e) {
            log.error(req, e.toString(), e);
            return Result.error(req,e.toString());
        }
        log.debug(req, "updateLimitFunction {} ", "end");
    
        if (bizCodeEnum== BizCode.SUCCESS){
            return Result.success(req);
        }else {
            return Result.error(req,bizCodeEnum);
        }
    }
    
    @RequestMapping(value="/10034", method=RequestMethod.POST)
    @ApiOperation(value = "删除接口限流", notes = "删除接口限流")
    @ResponseBody
    public Result<Res10034> deleteLimitFunction(@RequestBody GatewayRequest<Req10034> req) {
        log.debug(req, "deleteLimitFunction {}  ",  "begin");
        BizCodeEnum bizCodeEnum= BizCode.ERROR;
        ValidationUtils.validateEntityStr(req.getContent());
        try {
            if (StringUtils.isBlank(limitFunctionService.getLimitFunction(req.getContent().getFunctionCode()))){
                bizCodeEnum= BizErrorCode101.NO_LIMIT_FUNCTION;
            }else {
                if (limitFunctionService.deleteLimitFunction(req.getContent().getFunctionCode())){
                    bizCodeEnum= BizCode.SUCCESS;
                }
            }
        } catch (Exception e) {
            log.error(req, e.toString(), e);
            return Result.error(req,e.toString());
        }
        log.debug(req, "deleteLimitFunction {}  ",  "end");
        if (bizCodeEnum== BizCode.SUCCESS){
            return Result.success(req);
        }else {
            return Result.error(req,bizCodeEnum);
        }
    }
    */
}
